/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smary.ejb.entity;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *  Entität zur Speicherung der Userstories.
 * Hat folgende Beziehungen:
 *      1 zu N Definitionofdone Entität
 *      N zu 1 Productbacklog Entität
 *      1 zu N Tasks Entität
 * @author Alexander Cannell
 */
@Entity
@Table(name = "USERSTORY")
@XmlRootElement
@NamedQueries({
    
    @NamedQuery(name = "Userstory.findAll", query = "SELECT u FROM Userstory u"),
    @NamedQuery(name = "Userstory.findByUserstoryid", query = "SELECT u FROM Userstory u WHERE u.userstoryid = :userstoryid"),
    @NamedQuery(name = "Userstory.findByStorybezeichnung", query = "SELECT u FROM Userstory u WHERE u.storybezeichnung = :storybezeichnung"),
    @NamedQuery(name = "Userstory.findByStorybeschreibung", query = "SELECT u FROM Userstory u WHERE u.storybeschreibung = :storybeschreibung"),
    @NamedQuery(name = "Userstory.findByProductbacklog", query = "SELECT u FROM Userstory u WHERE u.productbacklog = :productbacklog"),
    @NamedQuery(name = "Userstory.findByprioritaet", query = "SELECT u FROM Userstory u WHERE u.prioritaet = :prioritaet"),
})
public class Userstory implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "USERSTORYID")
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Integer userstoryid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 2048)
    @Column(name = "STORYBEZEICHNUNG")
    private String storybezeichnung;
    @Size(min = 1, max = 32700)
    @Column(name = "STORYBESCHREIBUNG")
    private String storybeschreibung;
//    @Basic(optional = false)
//    @NotNull
//    @Column(name = "BACKLOGID")
//    private int backlogid;
    @Basic(optional = false)
    @NotNull
    @Column(name = "prioritaet")
    private int prioritaet;

    @ManyToOne
    @JoinColumn(name="BACKLOGID",
            referencedColumnName="PRODUCTBACKLOGID")
    protected  Productbacklog productbacklog;
    
    @OneToMany(mappedBy="userstory")
    protected Set<Definitionofdone> definitionofdone;

    public Set<Definitionofdone> getDefinitionofdone() {
        return definitionofdone;
    }

    public void setDefinitionofdone(Set<Definitionofdone> definitionofdone) {
        this.definitionofdone = definitionofdone;
    }

    @OneToMany(mappedBy="userstory")
    protected Set<Task> tasks;

    public Set<Task> getTasks() {
        return tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }
    

    public Productbacklog getProductbacklog() {
        return productbacklog;
    }

    public void setProductbacklog(Productbacklog productbacklog) {
        this.productbacklog = productbacklog;
    }
    
    
    
    public Userstory() {
    }

    public Userstory(Integer userstoryid) {
        this.userstoryid = userstoryid;
    }

    public Userstory(Integer userstoryid, String storybezeichnung, Productbacklog backlogid, int prioritaet) {
        this.userstoryid = userstoryid;
        this.storybezeichnung = storybezeichnung;
        this.productbacklog = backlogid;
        this.prioritaet = prioritaet;
    }

    public Integer getUserstoryid() {
        return userstoryid;
    }

    public void setUserstoryid(Integer userstoryid) {
        this.userstoryid = userstoryid;
    }

    public String getStorybezeichnung() {
        return storybezeichnung;
    }

    public void setStorybezeichnung(String storybezeichnung) {
        this.storybezeichnung = storybezeichnung;
    }

    public String getStorybeschreibung() {
        return storybeschreibung;
    }

    public void setStorybeschreibung(String storybeschreibung) {
        this.storybeschreibung = storybeschreibung;
    }

    public int getPrioritaet() {
        return prioritaet;
    }

    public void setPrioritaet(int prioritaet) {
        this.prioritaet = prioritaet;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userstoryid != null ? userstoryid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Userstory)) {
            return false;
        }
        Userstory other = (Userstory) object;
        if ((this.userstoryid == null && other.userstoryid != null) || (this.userstoryid != null && !this.userstoryid.equals(other.userstoryid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return userstoryid + getStorybezeichnung();
    }
    
}
